package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.ClassesEntity;
import com.company.project.service.ClassesService;



/**
 * 班级表
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2025-06-25 14:52:44
 */
@Controller
@RequestMapping("/")
public class ClassesController {
    @Autowired
    private ClassesService classesService;

    /**
    * 跳转到页面
    */
    @GetMapping("classes/list")
    public String classes() {
        return "classes/list";
    }


    @ApiOperation(value = "查询分页数据")
    @PostMapping("classes/listByPage")
    @SaCheckPermission("classes:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody ClassesEntity classes){
        LambdaQueryWrapper<ClassesEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        queryWrapper.eq(classes.getId() != null, ClassesEntity::getId, classes.getId());
        queryWrapper.orderByDesc(ClassesEntity::getId);
        IPage<ClassesEntity> iPage = classesService.page(classes.getQueryPage(), queryWrapper);
        iPage.getRecords().forEach(item -> {
            if (item.getStatus()==1){
                item.setStatusName("正常");
            }else {
                item.setStatusName("停用");
            }

        });
        return DataResult.success(iPage);
    }


    @ApiOperation(value = "新增")
    @PostMapping("classes/add")
    @SaCheckPermission("classes:add")
    @ResponseBody
    public DataResult add(@RequestBody ClassesEntity classes){
            classesService.save(classes);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("classes/delete")
    @SaCheckPermission("classes:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
            classesService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("classes/update")
    @SaCheckPermission("classes:update")
    @ResponseBody
    public DataResult update(@RequestBody ClassesEntity classes){
            classesService.updateById(classes);
        return DataResult.success();
    }



}
